package com.skzh.history.service.impl;

import java.util.List;
        import com.skzh.common.utils.DateUtils;
import com.skzh.flightplans.domain.Waypoints;
import com.skzh.flightplans.mapper.WaypointsMapper;
import com.skzh.history.utils.KmlUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.skzh.history.mapper.TaskHistoryMapper;
import com.skzh.history.domain.TaskHistory;
import com.skzh.history.service.ITaskHistoryService;

/**
 * 任务执行记录Service业务层处理
 *
 * @author skzh
 * @date 2025-04-08
 */
@Service
public class TaskHistoryServiceImpl implements ITaskHistoryService {
    @Autowired
    private TaskHistoryMapper taskHistoryMapper;
    @Autowired
    private WaypointsMapper waypointsMapper;

    /**
     * 查询任务执行记录
     *
     * @param recordId 任务执行记录主键
     * @return 任务执行记录
     */
    @Override
    public TaskHistory selectTaskHistoryByRecordId(Long recordId) {
        String fpId = String.valueOf(taskHistoryMapper.selectTaskHistoryByRecordId(recordId).getFpId());
        Waypoints waypoints = new Waypoints();
        waypoints.setWpFlightPlanId(fpId);
        if (fpId != null) {
            List<Waypoints>waypointsList  = waypointsMapper.selectWaypointsList(waypoints);
            KmlUtils.setWaypointsList(waypointsList);
        }
        return taskHistoryMapper.selectTaskHistoryByRecordId(recordId);
    }

    /**
     * 查询任务执行记录列表
     *
     * @param taskHistory 任务执行记录
     * @return 任务执行记录
     */
    @Override
    public List<TaskHistory> selectTaskHistoryList(TaskHistory taskHistory) {
        return taskHistoryMapper.selectTaskHistoryList(taskHistory);
    }

    /**
     * 新增任务执行记录
     *
     * @param taskHistory 任务执行记录
     * @return 结果
     */
    @Override
    public int insertTaskHistory(TaskHistory taskHistory) {
                taskHistory.setCreateTime(DateUtils.getNowDate());
            return taskHistoryMapper.insertTaskHistory(taskHistory);
    }

    /**
     * 修改任务执行记录
     *
     * @param taskHistory 任务执行记录
     * @return 结果
     */
    @Override
    public int updateTaskHistory(TaskHistory taskHistory) {
        return taskHistoryMapper.updateTaskHistory(taskHistory);
    }

    /**
     * 批量删除任务执行记录
     *
     * @param recordIds 需要删除的任务执行记录主键
     * @return 结果
     */
    @Override
    public int deleteTaskHistoryByRecordIds(Long[] recordIds) {
        return taskHistoryMapper.deleteTaskHistoryByRecordIds(recordIds);
    }

    /**
     * 删除任务执行记录信息
     *
     * @param recordId 任务执行记录主键
     * @return 结果
     */
    @Override
    public int deleteTaskHistoryByRecordId(Long recordId) {
        return taskHistoryMapper.deleteTaskHistoryByRecordId(recordId);
    }
}
